package org.mics.mq.rocketmq.aliyun.normal;

import org.mics.mq.rocketmq.aliyun.config.RocketMqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.openservices.ons.api.bean.ProducerBean;

@Configuration
@EnableConfigurationProperties(value =RocketMqConfig.class )
@ConditionalOnProperty(prefix = "rocketmq",name = "enable",havingValue = "true")
public class ProducerClient {
    @Autowired
    private RocketMqConfig mqConfig;

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public ProducerBean buildProducer() {
        ProducerBean producer = new ProducerBean();
        producer.setProperties(mqConfig.getMqPropertie());
        return producer;
    }

}
